#include <stdio.h>
#include <stdlib.h>

#include "ff_wrap.h"

int main(int argc, char **argv)
{
	int ret = 0;
	st_ff_context ff_ctx;
	unsigned char data[1024];

	printf(">>>[test ff_init_muxer]...\n");
	ret = ff_init_muxer("test.avi", &ff_ctx, NULL);
	printf(">>>[test ff_init_muxer] ret = %d\n",ret);
	if(ret < 0)
		exit(1);
	
	int frame = 0;
	while(frame++ < 100)
	{
		ret = ff_write_audio_frame(&ff_ctx,data,1024);
		//printf(">>>[test ff_write_audio_frame] ret = %d\n",ret);

		ret = ff_write_video_frame(&ff_ctx,data,1024);
		//printf(">>>[test ff_write_video_frame] ret = %d\n",ret);
	}

	ret = ff_exit_muxer(&ff_ctx);
	printf(">>>[test ff_exit_muxer] ret = %d\n",ret);

	ret = ff_init_demuxer("test1.avi",&ff_ctx);
	printf(">>>[test ff_init_demuxer]ret = %d\n",ret);
	if(ret < 0)
		exit(1);
	getchar();

	AVPacket pkt;
	av_init_packet(&pkt);
	pkt.data = NULL;
	pkt.size = 0;
	while(av_read_frame(ff_ctx.fmt_ctx,&pkt)>=0)
	{
		printf(">>>pkt.size = %d\n",pkt.size);
		av_free_packet(&pkt);
	}
	printf(">>> read frame end!\n");
	
	ret = ff_exit_demuxer(&ff_ctx);
	printf(">>>[test ff_exit_demuxer]ret = %d\n",ret);

	return 0;
}

